import request from "@/utils/request.ts";
import type {User, UserResponseData,AllRoleResponseData,SetRoleData} from './type.ts'
enum API {
    ALLUSER_URL='/admin/acl/user/',//获取所有的用户的信息
    ADDUSER_URL='/admin/acl/user/save',//添加一个新的用户账号
    UPDATEUSER_URL='/admin/acl/user/update',//更新用户信息
    ALLROLE_URL='/admin/acl/user/toAssign/',//获取全部职位，当前账号拥有的职位接口
    SETROLE_URL='/admin/acl/user/doAssignRole',//分配职务
    DELETEUSER_URL='/admin/acl/user/remove/',//删除某一个账号
    DELETEALLUSER_URL='/admin/acl/user/batchRemove',//批量删除用户
}
/**
 * 获取用户账号信息
 * @param page
 * @param limit
 * @param userName
 */
export const reqUserInfo = (page:number,limit:number,userName:string) => {
    return request.get<any,UserResponseData>(API.ALLUSER_URL+`${page}/${limit}/?username=${userName}`)
}
/**
 * 添加或修改用户信息
 * @param data
 */
export const reqAddOrUpdateUser = (data:User) => {
    if(data.id){
        return request.put<any>(API.UPDATEUSER_URL,data)
    }else {
        return request.post<any>(API.ADDUSER_URL,data)
    }
}
/**
 * 获取全部职位和当前用户的职位
 * @param adminId
 */
export const reqAllRole = (adminId:number) => {
    return request.get<any,AllRoleResponseData>(API.ALLROLE_URL+adminId)
}
/**
 * 分配职位
 * @param data
 */
export const reqSetRole = (data:SetRoleData) => {
  return request.post<any,any>(API.SETROLE_URL,data)
}
/**
 * 删除一个用户
 * @param id 用户ID
 */
export const reqRemoveUser = (id:number) => {
  return request.delete<any,any>(API.DELETEUSER_URL+id)
}
/**
 * 批量删除
 * @param idList
 */
export const reqRemoveUsers = (idList:number[]) => {
  return request.delete(API.DELETEALLUSER_URL,{data:idList})
}